<%-- Copyright (c) 2010 Canadensys --%>
<%-- JSP container for processing download.ftl page --%>
<%@ include file="_inc/functions.jsp" %>
<%  String TEMPLATE_PATH = "download.ftl"; %>
<%@ include file="_inc/ftl/processStart.jsp" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.util.UUID" %>
<%@ page import="net.canadensys.dataportal.vascan.LookupManager" %>
<%@ page import="net.canadensys.dataportal.vascan.TaxonManager" %>
<%
try{
	String filename ="";
	// set requested format
	String format = "dwc";
    if(request.getParameter("format") != null){
        format = request.getParameter("format");
    }
    
    // generate filename based on requested format
    if(format.equals("txt"))
        filename = ApplicationConfig.CSV_FILE_PREFIX + UUID.randomUUID() + ApplicationConfig.CSV_FILE_EXT;
    else
        filename = ApplicationConfig.DARWIN_CORE_FILE_ARCHIVE_PREFIX + UUID.randomUUID() + ApplicationConfig.DARWIN_CORE_FILE_ARCHIVE_EXT;
    
    root.put("filename",filename);
    root.put("downloadURL",InstallationConfig.getInstance().get(InstallationConfig.PUBLIC_DOWNLOAD_URL_KEY) + filename);
    // we also add the filename as a session attribute because the download script creates an ajax query to the file... as a precaution,
    // we don't want the filename to be accessible in the client but only as a session variable.
    session.setAttribute("filename",filename);
    root.put("format",format);
}
catch(Exception e){
    e.printStackTrace();
}
%>
<%@ include file="_inc/ftl/processStop.jsp" %>